QuickOPC User's Guide and Reference
Display Errors with ErrorProvider
Development Models > Live Binding Model > Live Binding Model for OPC Data (Classic and UA) > Typical Binding Scenarios > Display Errors with ErrorProvider
In This Topic

Windows Forms

The standard ErrorProvider extender is useful for displaying OPC operation error icons, with tooltips.

How to configure this feature:

Drag the ErrorProvider extender (standard Microsoft component) from the toolbox to the form. Configure the binding in a usual way.

Then, use the "Edit Live Bindings" command, "Clone" the existing binding, and change the cloned binding as follows: Set the  ArgumentsPath to ErrorMessage. Set the ValueTarget.ExtenderProvider to the ErrorProvider component on your form, and set the ValueTarget.TargetMember to the Error member. All in all, this will cause the error message from the OPC-DA item (or OPC-UA node attribute) be stored into the error text displayed by the ErrorProvider for the control.

Note: If you configure this with explicit Read or Write operations (not with Subscribe), you need to set up a binding group, assign related bindings to the same group, and have the operation invoked on a binding group.

WPF

Configure the binding in a usual way.

Place the ErrorProvider extender (this is not a standard Microsoft component) from the toolbox items onto the Component Tray. Configure the binding in a usual way.

Then, use the "Edit Live Bindings" command, "Clone" the existing binding, and change the cloned binding as follows: Set the ArgumentsPath to ErrorMessage. Set the ValueTarget.ExtenderProvider to the ErrorProvider component on your form, and set the ValueTarget.TargetMember to the Error member. All in all, this will cause the error message from the OPC-UA be stored into the error text displayed by the ErrorProvider for the control.

Note: If you configure this with explicit Read or Write operations (not with Subscription), you need to set up a binding group, assign related bindings to the same group, and have the operation invoked on a binding group.

Tip: The standard Validation.ErrorTemplate simply displays a red rectangle around control, but without the error text. In order to display the error text as well, you need to use styles - define your own Validation.ErrorTemplate in XAML <Window.Resource>. Then, set Validation.ErrorTemplate="{StaticResource ErrorTemplate}" for the control.

ErrorTemplate example (indicates the error by a red circle with an exclamation mark, and the error text):

<Window.Resources>
        <Style x:Key="BlinkedEllipse" TargetType="{x:Type Ellipse}">
            <Style.Triggers>
                <EventTrigger RoutedEvent="Ellipse.Loaded">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:0.5" AutoReverse="True" RepeatBehavior="3x"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Style.Triggers>
        </Style>
        <ControlTemplate x:Key="ErrorTemplate">
            <DockPanel LastChildFill="True">
                <Grid Width="16" Height="16" DockPanel.Dock="Right">
                    <Ellipse Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center" Stroke="Black" StrokeThickness="1" ToolTip="{Binding AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=ErrorAdorner}" Style="{StaticResource BlinkedEllipse}">
                        <Ellipse.Fill>
                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" >
                                <GradientStop Color="White" Offset="0" />
                                <GradientStop Color="Red" Offset="1.0" />
                            </LinearGradientBrush>
                        </Ellipse.Fill>
                    </Ellipse>
                    <TextBlock Foreground="White" FontWeight="Heavy" FontSize="12" HorizontalAlignment="Center" 
                                        VerticalAlignment="Center" TextAlignment="Center"
                        ToolTip="{Binding AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=ErrorAdorner}"                                     
                                        Text="!"/>
                </Grid>
                <AdornedElementPlaceholder x:Name="ErrorAdorner" />
            </DockPanel>
        </ControlTemplate>        
</Window.Resources>   

Tip: If ErrorProvider is used in binding for control that is inside TabItem or GroupBox, then <AdornerDecorator> should be used, see:

<GroupBox>
    <AdornerDecorator>
        <Grid>
            <TextBox> <!-- TextBox with LiveBinding using ErrorProvider !-->
            </TextBox>
        </Grid>
    </AdornerDecorator>
</GroupBox>

 

See Also